package com.oplink.webems.modules.alarm.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.Valid;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.search.annotations.IndexedEmbedded;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.oplink.webems.modules.cfg.entity.CfgNe;
import com.oplink.webems.modules.cfg.entity.CfgSlot;

/**
 * History Alarm Entity
 * @author yizhang
 */
@Entity
@Table(name = "alarm_his")
@DynamicInsert @DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AlarmHistory {

	//ID
	private Long id;
	
	//机盘号
    private CfgSlot slot;
	
	//告警ID
    private String aid;
    
	//告警索引号
    private String aidx;
    
    //Trap类型（底层称为告警类型，分为fault,event,restore，即错误、事件、恢复三种）
    private TrapType traptype;
    
    //告警类型（底层称为网元管理类型）
    private AlarmType atype;
    
    //机架号（来自于位置信息）
    private int chassis;
    
    //端口号（来自于位置信息）
    private int port;
    
    //严重程度（底程称为告警等级）
    private AlarmSeverity severity;
    
    //告警时间(发生时间)
    private Date adate;
    
    //位置信息(告警位置)
    private String position;
    
    //工作模式
    private AlarmOpsmMode amode;
    
    //SCC端口ID
    private String sccport;
	
    //位置信息(通道位置)
	private String opsmposition;
	
	//恢复时间
	private Date rdate;
	
	//确认时间
	private Date cdate;
	
	//网元
    private CfgNe nenode;
    
    private String btimes;
    
    private String etimes;
    
    private String timetype;
    
    //告警状态（确认、恢复）
    private AlarmStatus status;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="slot")
	@NotFound(action = NotFoundAction.IGNORE)	
	@JsonIgnore
	public CfgSlot getSlot() {
		return slot;
	}

	public void setSlot(CfgSlot slot) {
		this.slot = slot;
	}

	public String getAid() {
		return aid;
	}

	public void setAid(String aid) {
		this.aid = aid;
	}

	public String getAidx() {
		return aidx;
	}

	public void setAidx(String aidx) {
		this.aidx = aidx;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="traptype")
	@NotFound(action = NotFoundAction.IGNORE)	
	@JsonIgnore	
	public TrapType getTraptype() {
		return traptype;
	}

	public void setTraptype(TrapType traptype) {
		this.traptype = traptype;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="alarmtype")
	@NotFound(action = NotFoundAction.IGNORE)	
	@JsonIgnore	
	public AlarmType getAtype() {
		return atype;
	}

	public void setAtype(AlarmType atype) {
		this.atype = atype;
	}

	public int getChassis() {
		return chassis;
	}

	public void setChassis(int chassis) {
		this.chassis = chassis;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="severity")
	@NotFound(action = NotFoundAction.IGNORE)	
	@JsonIgnore		
	public AlarmSeverity getSeverity() {
		return severity;
	}

	public void setSeverity(AlarmSeverity severity) {
		this.severity = severity;
	}

	public Date getAdate() {
		return adate;
	}

	public void setAdate(Date adate) {
		this.adate = adate;
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="omode")
	@NotFound(action = NotFoundAction.IGNORE)	
	@JsonIgnore	
	public AlarmOpsmMode getAmode() {
		return amode;
	}

	public void setAmode(AlarmOpsmMode amode) {
		this.amode = amode;
	}

	public String getSccport() {
		return sccport;
	}

	public void setSccport(String sccport) {
		this.sccport = sccport;
	}

	public String getOpsmposition() {
		return opsmposition;
	}

	public void setOpsmposition(String opsmposition) {
		this.opsmposition = opsmposition;
	}

	public Date getRdate() {
		return rdate;
	}

	public void setRdate(Date rdate) {
		this.rdate = rdate;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="neid")
	@NotFound(action = NotFoundAction.IGNORE)	
	@JsonIgnore		
	public CfgNe getNenode() {
		return nenode;
	}

	public void setNenode(CfgNe nenode) {
		this.nenode = nenode;
	}

	public Date getCdate() {
		return cdate;
	}

	public void setCdate(Date cdate) {
		this.cdate = cdate;
	}

	@Transient
	public String getBtimes() {
		return btimes;
	}

	public void setBtimes(String btimes) {
		this.btimes = btimes;
	}

	@Transient
	public String getEtimes() {
		return etimes;
	}

	public void setEtimes(String etimes) {
		this.etimes = etimes;
	}

	@Transient
	public String getTimetype() {
		return timetype;
	}

	public void setTimetype(String timetype) {
		this.timetype = timetype;
	}

	@OneToOne(mappedBy="ahist",cascade=CascadeType.ALL,optional=false) 
	@IndexedEmbedded
	public AlarmStatus getStatus() {
		return status;
	}

	public void setStatus(AlarmStatus status) {
		this.status = status;
	}

	
	

}

